#include<stdio.h>
#include<sys/shm.h>
#include<fcntl.h>
#include<string.h>
int main(){
    //获取共享内存
    int shm_id = shmget(0x23232323, 1024, IPC_CREAT | 0664);
    if(shm_id < 0){
        perror("shmget");
        return 0;
    }
    //附加
    void* addr = shmat(shm_id, NULL, SHM_RDONLY);
    if(addr == NULL){
        perror("shmat");
        return 0;
    }
    //读
    printf("%s\n", (char*)addr);
    //分离
    shmdt(addr);
    return 0;
}

